﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Weburls.TopurlView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="顶级菜单设置"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:TopurlViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot" Margin="6">
        <Grid Visibility="{Binding ShowUpdate, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="240" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>

                <TextBlock VerticalAlignment="Center" Text="平台：" />

                <ComboBox Grid.Column="1"
                          VerticalAlignment="Center"
                          ItemsSource="{Binding PlatformCollection}"
                          SelectedItem="{Binding SelectedPlatform,
                                                 Mode=TwoWay}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Converter={StaticResource EnumTranslationConverter}, ConverterParameter=PLATFORMTYPE}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>

                <TextBlock Grid.Column="2"
                           Margin="12,0,0,0"
                           VerticalAlignment="Center"
                           Text="关键字：" />

                <TextBox Grid.Column="3"
                         VerticalAlignment="Center"
                         Text="{Binding Keywords,
                                        Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}" />

                <Button Grid.Column="5"
                        Width="60"
                        VerticalAlignment="Center"
                        Command="{Binding InsertCommand}"
                        Content="新增" />

            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   Margin="0,6"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid AutoGenerateColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding ShowCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Title}" Header="标题" />
                        <sdk:DataGridTextColumn Binding="{Binding Url}" Header="链接地址" />
                        <sdk:DataGridTextColumn Binding="{Binding IdentifyCode}" Header="识别码" />
                        <sdk:DataGridTextColumn Binding="{Binding Icon}" Header="图标" />
                        <sdk:DataGridTextColumn Binding="{Binding Index}" Header="索引位置" />
                        <sdk:DataGridCheckBoxColumn Binding="{Binding ShowToAll}" Header="是否公开" />
                        <sdk:DataGridTemplateColumn Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                        <HyperlinkButton Margin="12,0" Content="编辑">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <StackPanel Grid.Row="2"
                        Margin="5"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Stretch"
                        Orientation="Horizontal">
                <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />

                <Button Margin="6,0"
                        Command="{Binding PreviousPageCommand}"
                        Style="{StaticResource PreviousPageButtonStyle}" />

                <TextBlock x:Name="CurrentPagePrefixTextBlock"
                           Width="Auto"
                           Margin="4,0,0,0"
                           VerticalAlignment="Center">
                    <Run Text="当前第 " />
                    <Run Text="{Binding Index}" />
                    <Run Text=" 页，共" />
                    <Run Text="{Binding PagesCount}" />
                    <Run Text=" 页" />
                </TextBlock>

                <Button Margin="6,0"
                        Command="{Binding NextPageCommand}"
                        Style="{StaticResource NextPageButtonStyle}" />
                <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
            </StackPanel>
        </Grid>

        <Grid Visibility="{Binding ShowUpdate, Converter={StaticResource BooleanToVisibilityConverter}}">

            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <StackPanel>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="平台：" />
                        <ComboBox Grid.Column="1"
                                  VerticalAlignment="Center"
                                  IsEnabled="{Binding IsInsert}"
                                  ItemsSource="{Binding PlatformCollection}"
                                  SelectedItem="{Binding UpdateEntity.PlatformType,
                                                         Mode=TwoWay,
                                                         UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="标题：" />
                        <TextBox Grid.Column="1"
                                 VerticalAlignment="Center"
                                 Text="{Binding UpdateEntity.Title,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="链接地址：" />
                        <TextBox Grid.Column="1"
                                 VerticalAlignment="Center"
                                 Text="{Binding UpdateEntity.Url,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="识别码：" />
                        <TextBox Grid.Column="1"
                                 VerticalAlignment="Center"
                                 Text="{Binding UpdateEntity.IdentifyCode,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="图标：" />
                        <TextBox Grid.Column="1"
                                 VerticalAlignment="Center"
                                 Text="{Binding UpdateEntity.Icon,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="索引位置：" />
                        <TextBox Grid.Column="1"
                                 VerticalAlignment="Center"
                                 Text="{Binding UpdateEntity.Index,
                                                Mode=TwoWay,
                                                UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>

                    <Grid Margin="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock HorizontalAlignment="Right"
                                   VerticalAlignment="Center"
                                   Text="公开：" />
                        <CheckBox Grid.Column="1"
                                  VerticalAlignment="Center"
                                  IsChecked="{Binding UpdateEntity.ShowToAll,
                                                      Mode=TwoWay,
                                                      UpdateSourceTrigger=PropertyChanged}" />
                    </Grid>
                </StackPanel>

                <StackPanel Grid.Row="1" Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>

            </Grid>

            <ListBox Grid.Column="1"
                     ItemsSource="{Binding IconCollection}"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                     SelectedItem="{Binding UpdateEntity.Icon,
                                            Mode=TwoWay}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <toolkit:WrapPanel />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>

                        <Grid Grid.Column="1"
                              Margin="6"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center">
                            <Grid Grid.ColumnSpan="2"
                                  Background="White"
                                  Opacity="0" />
                            <Path x:Name="path"
                                  Width="36"
                                  Height="36"
                                  Margin="0"
                                  Data="{Binding Converter={StaticResource KeyToPathGeometryConverter}}"
                                  Fill="Gray"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform Angle="0" />
                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>
</navigation:PageView>
